package com.tyqx.apiutil.common;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.core.io.Resource;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tyqx.apiutil.common.GetUrlUtil;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

public class RestTemplateUtil {

    private static  HttpHeaders headers;
    private static HttpEntity<Resource> httpEntity;
    private static RestTemplate template;
    public static String getUrl(String httpUrl) {
        try {
            headers = new HttpHeaders();
            headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36");
            httpEntity = new HttpEntity<Resource>(headers);
            template = new RestTemplate();
            ResponseEntity<byte[]> response = template.exchange(httpUrl, HttpMethod.GET,
                    httpEntity, byte[].class);
            response.getBody();
            String body = new String(response.getBody());
            return body;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
